<!DOCTYPE html>
<html lang="en">
<head prefix="og: http://ogp.me/ns#">
  <meta charset="utf-8">
  <title>starRTC文档</title>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Canonical links -->
  <link rel="canonical" href="https://starrtc.gitee.io/en/docs/web-3.html">
  <!-- Alternative links -->
  
    
      <link rel="alternative" hreflang="en" href="https://starrtc.gitee.io/docs/web-3.html">
    
      <link rel="alternative" hreflang="zh-cn" href="https://starrtc.gitee.io/zh-cn/docs/web-3.html">
    
  
  <!-- Icon -->
  <link rel="apple-touch-icon" sizes="57x57" href="/icon/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="114x114" href="/icon/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="72x72" href="/icon/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="144x144" href="/icon/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="60x60" href="/icon/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="120x120" href="/icon/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="76x76" href="/icon/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="152x152" href="/icon/apple-touch-icon-152x152.png">
  <link rel="icon" type="image/png" href="/icon/favicon-196x196.png" sizes="196x196">
  <link rel="icon" type="image/png" href="/icon/favicon-160x160.png" sizes="160x160">
  <link rel="icon" type="image/png" href="/icon/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="/icon/favicon-16x16.png" sizes="16x16">
  <link rel="icon" type="image/png" href="/icon/favicon-32x32.png" sizes="32x32">
  <meta name="msapplication-TileColor" content="#2f83cd">
  <meta name="msapplication-TileImage" content="/icon/mstile-144x144.png">
  <!-- CSS -->
  <!-- build:css build/css/navy.css -->
  <link rel="stylesheet" href="/css/navy.css">
  <!-- endbuild -->
  <link href="https://starrtc.gitee.io/googleapis.css" rel="stylesheet" type="text/css">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> 
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css">
  <!-- RSS -->
  <link rel="alternate" href="/atom.xml" title="starRTC文档">
  <!-- Open Graph -->
  <meta name="description" content="Initialize &amp;amp; log in to the SDK3.1 Set ip and port Note： Please use https to access the url when trusting the certificate, while do not use http!!!  //Set msg server ip and websocket port. Note: If">
<meta property="og:type" content="website">
<meta property="og:title" content="starRTC文档">
<meta property="og:url" content="https://starrtc.gitee.io/en/docs/web-3.html">
<meta property="og:site_name" content="starRTC文档">
<meta property="og:description" content="Initialize &amp;amp; log in to the SDK3.1 Set ip and port Note： Please use https to access the url when trusting the certificate, while do not use http!!!  //Set msg server ip and websocket port. Note: If">
<meta property="og:locale" content="en">
<meta property="og:updated_time" content="2020-09-06T01:05:51.954Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="starRTC文档">
<meta name="twitter:description" content="Initialize &amp;amp; log in to the SDK3.1 Set ip and port Note： Please use https to access the url when trusting the certificate, while do not use http!!!  //Set msg server ip and websocket port. Note: If">
<meta name="twitter:site" content="hexojs">
<meta property="fb:admins" content="100000247608790">
  <!-- Google Analytics -->
  
</head>

<body>
  <div id="container">
    <header id="header" class="wrapper">
  <div id="header-inner" class="inner">
    <h1 id="logo-wrap">
      
      <a href="https://starrtc.gitee.io/" id="logo">starRTC</a>
    </h1>
    <nav id="main-nav">
      <a href="https://starrtc.gitee.io/" class="main-nav-link">Home</a><a href="https://blog.starRTC.com" class="main-nav-link">Blog</a><a href="https://github.com/starrtc/android-demo/issues" class="main-nav-link">Forum</a><a href="/en/docs/" class="main-nav-link">Docs</a><a href="/en/download/" class="main-nav-link">Download</a><a href="/en/contact/" class="main-nav-link">Contact</a>
      
    </nav>
    <div id="lang-select-wrap">
      <label id="lang-select-label"><i class="fa fa-globe"></i><span>English</span></label>
      <select id="lang-select" data-canonical="docs/web-3.html">
        
          <option value="en" selected>English</option>
        
          <option value="zh-cn">简体中文</option>
        
      </select>
    </div>
    <a id="mobile-nav-toggle">
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
    </a>
  </div>
</header>

    <div id="content-wrap">
  <div id="content" class="wrapper">
    <div id="content-inner">
      <article class="article-container" itemscope itemtype="http://schema.org/Article">
        <div class="article-inner">
          <div class="article">
            <div class="inner">
              <header class="article-header">
                <h1 class="article-title" itemprop="name"></h1>
                <a href="https://github.com/starRTC/docs/edit/master/en/docs/web-3.md" class="article-edit-link" title="Improve this doc"><i class="fa fa-pencil"></i></a>
              </header>
              <div class="article-content" itemprop="articleBody">
                <h1 id="Initialize-amp-log-in-to-the-SDK" class="article-heading"><a href="#Initialize-amp-log-in-to-the-SDK" class="headerlink" title="Initialize &amp; log in to the SDK"></a>Initialize &amp; log in to the SDK<a class="article-anchor" href="#Initialize-amp-log-in-to-the-SDK" aria-hidden="true"></a></h1><p>3.1 Set ip and port</p>
<p>Note： Please use https to access the url when trusting the certificate, while do not use http!!!</p>
<hr>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">//Set msg server ip and websocket port. Note: If you use the self-signed certificate on the server, and the url should be input from the browser before connecting for the first time at each computer.</span></span><br><span class="line"><span class="comment">//https://ip:29991 Trust certificate</span></span><br><span class="line">StarRtc.StarSDK.setMsgServerInfo(<span class="string">"ip"</span>, <span class="number">19903</span>) 					</span><br><span class="line"></span><br><span class="line"><span class="comment">//Set chatRoom connection ip and websocket port. Note: If you use the self-signed certificate on the server, and the url should be input from the browser before connecting for the first time at each computer.</span></span><br><span class="line">StarRtc.StarSDK.setChatRoomServerInfo(<span class="string">"ip"</span>, <span class="number">19906</span>) 			</span><br><span class="line"></span><br><span class="line"><span class="comment">//Set SrcServer connection ip, websocket port, webrtc port and webrtc ip (the webrtc ip is optional. If you do not fill in,the default value is the same ad the server ip)， Note: If you use the self-signed certificate on the server, and the url should be input from the browser before connecting for the first time at each computer.</span></span><br><span class="line"><span class="comment">//https://ip:29994 Trust certificate</span></span><br><span class="line">StarRtc.StarSDK.setSrcServerInfo(<span class="string">"ip"</span>, <span class="number">19934</span>, <span class="number">19935</span>, <span class="string">"webrtcIP"</span>)  			</span><br><span class="line"></span><br><span class="line"><span class="comment">//Set VdnServer connection ip, websocket port, webrtc port and webrtc ip (the webrtc ip is optional. If you do not fill in,the default value is the same ad the server ip)， Note: If you use the self-signed certificate on the server, and the url should be input from the browser before connecting for the first time at each computer.</span></span><br><span class="line"><span class="comment">//https://ip:29995 Trust certificate</span></span><br><span class="line">StarRtc.StarSDK.setVdnServerInfo(<span class="string">"ip"</span>, <span class="number">19940</span>, <span class="number">19941</span>, <span class="string">"webrtcIP"</span>) 			</span><br><span class="line"></span><br><span class="line"><span class="comment">//Set VoipServer connection ip, server port, websocket port, webrtc port and webrtc ip(the webrtc ip is optional. If you do not fill in,the default value is the same ad the server ip)， Note: If you use the self-signed certificate on the server, and the url should be input from the browser before connecting for the first time at each computer.</span></span><br><span class="line"><span class="comment">//https://ip:29992 Trust certificate</span></span><br><span class="line">StarRtc.StarSDK.setVoipServerInfo(<span class="string">"ip"</span>, <span class="number">10086</span>, <span class="number">10087</span>, <span class="number">10088</span>, <span class="string">"webrtcIP"</span>)</span><br></pre></td></tr></table></figure>
<h2 id="3-3-Logging-in-out-of-the-SDK" class="article-heading"><a href="#3-3-Logging-in-out-of-the-SDK" class="headerlink" title="3.3 Logging in/out of the SDK"></a>3.3 Logging in/out of the SDK<a class="article-anchor" href="#3-3-Logging-in-out-of-the-SDK" aria-hidden="true"></a></h2><p>Call the login method of StarRtc.StarSDK to log in to the SDK;</p>
<p>Sample：<br><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">callBack</span>(<span class="params">data,status</span>) </span>&#123;</span><br><span class="line">	<span class="keyword">switch</span> (status)&#123;</span><br><span class="line">		<span class="comment">//connection status</span></span><br><span class="line">		<span class="keyword">case</span> <span class="string">"connect success"</span>:</span><br><span class="line">		<span class="keyword">case</span> <span class="string">"connect failed"</span>:</span><br><span class="line">		<span class="keyword">case</span> <span class="string">"connect closed"</span>:</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		<span class="comment">//Receive the login message</span></span><br><span class="line">		<span class="keyword">case</span> <span class="string">"onLoginMessage"</span>:</span><br><span class="line">			<span class="built_in">console</span>.log(<span class="string">"login:"</span> + data.status);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//Login to the SDK</span></span><br><span class="line"><span class="keyword">var</span> starSDK = <span class="keyword">new</span> StarRtc.StarSDK();</span><br><span class="line">starSDK.login(appID,userId,callBack);</span><br><span class="line"></span><br><span class="line"><span class="comment">//Log out the SDK</span></span><br><span class="line">starSDK.logout();</span><br></pre></td></tr></table></figure></p>

              </div>
              <footer class="article-footer">
                <time class="article-footer-updated" datetime="2020-09-06T01:05:51.954Z" itemprop="dateModified">Last updated<script type="text/javascript">document.write("："+(new Date()).toISOString().slice(0,10))</script></time>
		<a href="index.html" class="article-footer-next" title="Overview"><span>Next</span><i class="fa fa-chevron-right"></i></a>
              </footer>
            </div>
          </div>
          <aside id="article-toc" role="navigation">
            <div id="article-toc-inner">
              <strong class="sidebar-title">Contents</strong>
              <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Initialize-amp-log-in-to-the-SDK"><span class="toc-text">Initialize &amp; log in to the SDK</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-3-Logging-in-out-of-the-SDK"><span class="toc-text">3.3 Logging in/out of the SDK</span></a></li></ol></li></ol>
              <a href="#" id="article-toc-top">Back to Top</a>
            </div>
          </aside>
        </div>
      </article>
      <aside id="sidebar" role="navigation">
  <div class="inner">
    <strong class="sidebar-title">Getting Started</strong><a href="index.html" class="sidebar-link">Overview</a><strong class="sidebar-title">Android</strong><a href="android-1.html" class="sidebar-link">1.prerequisite</a><a href="android-2.html" class="sidebar-link">2.SDK intro</a><a href="android-3b.html" class="sidebar-link">3b.init(private)</a><a href="android-4.html" class="sidebar-link">4.im</a><a href="android-5.html" class="sidebar-link">5.group msg</a><a href="android-6.html" class="sidebar-link">6.chatroom msg</a><a href="android-7.html" class="sidebar-link">7.voip</a><a href="android-8.html" class="sidebar-link">8.meeting</a><a href="android-9.html" class="sidebar-link">9.live</a><a href="android-10.html" class="sidebar-link">10.other components</a><a href="android-11.html" class="sidebar-link">11.super room</a><a href="android-user-list.html" class="sidebar-link">online user list</a><a href="android-beauty-callback.html" class="sidebar-link">beauty</a><a href="android-errCode.html" class="sidebar-link">ErrorCode</a><strong class="sidebar-title">iOS</strong><a href="ios-1.html" class="sidebar-link">1.prerequisite</a><a href="ios-2.html" class="sidebar-link">2.SDK intro</a><a href="ios-3b.html" class="sidebar-link">3b.init(private)</a><a href="ios-4.html" class="sidebar-link">4.im</a><a href="ios-5.html" class="sidebar-link">5.group msg</a><a href="ios-6.html" class="sidebar-link">6.chatroom msg</a><a href="ios-7.html" class="sidebar-link">7.voip</a><a href="ios-8.html" class="sidebar-link">8.meeting</a><a href="ios-9.html" class="sidebar-link">9.live</a><a href="ios-10.html" class="sidebar-link">10.voip direct connection</a><strong class="sidebar-title">web</strong><a href="web-1.html" class="sidebar-link">1.prerequisite</a><a href="web-2.html" class="sidebar-link">2.SDK intro</a><a href="web-4.html" class="sidebar-link">4.im</a><a href="web-5.html" class="sidebar-link">5.group msg</a><a href="web-6.html" class="sidebar-link">6.chatroom msg</a><a href="web-7.html" class="sidebar-link">7.voip</a><a href="web-8.html" class="sidebar-link">8.meeting</a><a href="web-9.html" class="sidebar-link">9.live</a><a href="web-10.html" class="sidebar-link">10.private</a><strong class="sidebar-title">Win PC</strong><a href="win-1.html" class="sidebar-link">1.prerequisite</a><a href="win-2.html" class="sidebar-link">2.init</a><a href="win-3.html" class="sidebar-link">3.im</a><a href="win-4.html" class="sidebar-link">4.group msg</a><a href="win-5.html" class="sidebar-link">5.chatroom msg</a><a href="win-6.html" class="sidebar-link">6.voip</a><a href="win-7.html" class="sidebar-link">7.meeting</a><a href="win-8.html" class="sidebar-link">8.live</a><strong class="sidebar-title">Server API</strong><a href="aec-index.html" class="sidebar-link">Overview</a><a href="aec-group.html" class="sidebar-link">group events</a><a href="aec-chatroom.html" class="sidebar-link">chatroom events</a><a href="aec-voip.html" class="sidebar-link">voip events</a><a href="aec-channel.html" class="sidebar-link">音视频流事件通知</a><a href="aec-other.html" class="sidebar-link">other events</a>
  </div>
</aside>
    </div>
  </div>
</div>

    <footer id="footer" class="wrapper">
  <div class="inner">
    <div id="footer-copyright">
      &copy; 2010-2020 <a href="https://starrtc.gitee.io/" target="_blank">starRTC</a><br>
    </div>
    <div id="footer-links">
      <a href="https://gitee.com/starrtc" class="footer-link" target="_blank"><i class="fa fa-github-alt"></i></a>
    </div>
  </div>
</footer>

  </div>
  <div id="mobile-nav-dimmer"></div>
  <nav id="mobile-nav">
  <div id="mobile-nav-inner">
    <ul id="mobile-nav-list">
      <a href="https://starrtc.gitee.io/" class="main-nav-link">Home</a><a href="https://blog.starRTC.com" class="main-nav-link">Blog</a><a href="https://github.com/starrtc/android-demo/issues" class="main-nav-link">Forum</a><a href="/en/docs/" class="mobile-nav-link">Docs</a><a href="/en/download/" class="mobile-nav-link">Download</a><a href="/en/contact/" class="mobile-nav-link">Contact</a>
      <li class="mobile-nav-item">
        <a href="https://github.com/starrtc" class="mobile-nav-link" rel="external" target="_blank">GitHub</a>
      </li>
    </ul>
    
      <strong class="mobile-nav-title">Getting Started</strong><a href="index.html" class="mobile-nav-link">Overview</a><strong class="mobile-nav-title">Android</strong><a href="android-1.html" class="mobile-nav-link">1.prerequisite</a><a href="android-2.html" class="mobile-nav-link">2.SDK intro</a><a href="android-3b.html" class="mobile-nav-link">3b.init(private)</a><a href="android-4.html" class="mobile-nav-link">4.im</a><a href="android-5.html" class="mobile-nav-link">5.group msg</a><a href="android-6.html" class="mobile-nav-link">6.chatroom msg</a><a href="android-7.html" class="mobile-nav-link">7.voip</a><a href="android-8.html" class="mobile-nav-link">8.meeting</a><a href="android-9.html" class="mobile-nav-link">9.live</a><a href="android-10.html" class="mobile-nav-link">10.other components</a><a href="android-11.html" class="mobile-nav-link">11.super room</a><a href="android-user-list.html" class="mobile-nav-link">online user list</a><a href="android-beauty-callback.html" class="mobile-nav-link">beauty</a><a href="android-errCode.html" class="mobile-nav-link">ErrorCode</a><strong class="mobile-nav-title">iOS</strong><a href="ios-1.html" class="mobile-nav-link">1.prerequisite</a><a href="ios-2.html" class="mobile-nav-link">2.SDK intro</a><a href="ios-3b.html" class="mobile-nav-link">3b.init(private)</a><a href="ios-4.html" class="mobile-nav-link">4.im</a><a href="ios-5.html" class="mobile-nav-link">5.group msg</a><a href="ios-6.html" class="mobile-nav-link">6.chatroom msg</a><a href="ios-7.html" class="mobile-nav-link">7.voip</a><a href="ios-8.html" class="mobile-nav-link">8.meeting</a><a href="ios-9.html" class="mobile-nav-link">9.live</a><a href="ios-10.html" class="mobile-nav-link">10.voip direct connection</a><strong class="mobile-nav-title">web</strong><a href="web-1.html" class="mobile-nav-link">1.prerequisite</a><a href="web-2.html" class="mobile-nav-link">2.SDK intro</a><a href="web-4.html" class="mobile-nav-link">4.im</a><a href="web-5.html" class="mobile-nav-link">5.group msg</a><a href="web-6.html" class="mobile-nav-link">6.chatroom msg</a><a href="web-7.html" class="mobile-nav-link">7.voip</a><a href="web-8.html" class="mobile-nav-link">8.meeting</a><a href="web-9.html" class="mobile-nav-link">9.live</a><a href="web-10.html" class="mobile-nav-link">10.private</a><strong class="mobile-nav-title">Win PC</strong><a href="win-1.html" class="mobile-nav-link">1.prerequisite</a><a href="win-2.html" class="mobile-nav-link">2.init</a><a href="win-3.html" class="mobile-nav-link">3.im</a><a href="win-4.html" class="mobile-nav-link">4.group msg</a><a href="win-5.html" class="mobile-nav-link">5.chatroom msg</a><a href="win-6.html" class="mobile-nav-link">6.voip</a><a href="win-7.html" class="mobile-nav-link">7.meeting</a><a href="win-8.html" class="mobile-nav-link">8.live</a><strong class="mobile-nav-title">Server API</strong><a href="aec-index.html" class="mobile-nav-link">Overview</a><a href="aec-group.html" class="mobile-nav-link">group events</a><a href="aec-chatroom.html" class="mobile-nav-link">chatroom events</a><a href="aec-voip.html" class="mobile-nav-link">voip events</a><a href="aec-channel.html" class="mobile-nav-link">音视频流事件通知</a><a href="aec-other.html" class="mobile-nav-link">other events</a>
    
  </div>
  <div id="mobile-lang-select-wrap">
    <span id="mobile-lang-select-label"><i class="fa fa-globe"></i><span>English</span></span>
    <select id="mobile-lang-select" data-canonical="docs/web-3.html">
      
        <option value="en" selected>English</option>
      
        <option value="zh-cn">简体中文</option>
      
    </select>
  </div>
</nav>
  <!-- Scripts -->
<!-- build:js build/js/main.js -->
<script src="/js/lang_select.js"></script>
<script src="/js/toc.js"></script>
<script src="/js/mobile_nav.js"></script>
<!-- endbuild -->
<!-- Algolia -->

<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
<script type="text/javascript">
document.getElementById('search-input-wrap').classList.add('on');
docsearch({
  apiKey: 'c3d5d4c995b5e0c2ffb5623900279a66',
  indexName: 'hexo',
  inputSelector: '#search-input'
});
</script>


</body>
</html>